package main

import (
	"fmt"
	"go_redis_service/config"
	"go_redis_service/constant"
	"go_redis_service/lib/info"
	"go_redis_service/lib/logger"
	"go_redis_service/resp/handler"
	"go_redis_service/tcp"
	"os"
)

func fileExists(fileName string) bool {
	info, err := os.Stat(fileName)
	return err == nil && !info.IsDir()
}

func main() {
	info.Logo()
	logger.Setup(constant.DefaultLogConfig)
	if fileExists(constant.ConfigFile) {
		config.SetupConfig(constant.ConfigFile)
	} else {
		config.Properties = constant.DefaultRedisConfig
	}
	err := tcp.ListenAndServeWithSignal(&tcp.Config{Address: fmt.Sprintf("%s:%d", config.Properties.Bind, config.Properties.Port)}, handler.NewHandler())
	if err != nil {
		fmt.Println(err)
	}
}
